package com.summer.core.web.action.admin;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.ParentPackage;

import com.summer.core.action.BaseAction;
import com.summer.core.web.bean.Menu;
import com.summer.core.web.service.MenuService;

/**
 * 后台Action类 - 菜单
 * @author wwwlike
 *
 */

@ParentPackage("admin")
public class MenuAction extends BaseAction<Menu, MenuService> {

	private Set<Menu> menuSet;
	private List<Menu> menuList;

	public Menu getMenu() {
		return getBean();
	}

	public void setMenu(Menu menu) {
		setBean(menu);
	}

	@Resource
	public void setService(MenuService service) {
		this.service = service;
	}
	
	//获得一级菜单
	public String getMainMenu() {
		dlist = getService().getList("parent.id", "0");
		return result("header");
	}

	//获得一级菜单下面的子菜单（2，3级菜单系统目前只支持2，3级菜单）
	public String subMenu() {
		String pid = bean.getParent().getId();
		menuSet = service.load(pid).getChildren();
		return result("subMenu");

	}

	// 商店配置
	public String setting() {
		return "setting";
	}

	// 会员
	public String member() {
		return "member";
	}

	// 商品
	public String product() {
		return "product";
	}

	// 页面管理
	public String content() {
		return "content";
	}

	// 订单管理
	public String order() {
		return "order";
	}

	// 管理员
	public String admin() {
		return "admin";
	}

	// 主体
	public String main() {
		return "main";
	}

	// 常用
	public String common() {
		menuList = service.getList("common",true);
		menuSet=new HashSet<Menu>();
		for(Menu menu:menuList)
		{
			menuSet.add(menu);
		}
		return result("subMenu");
	}

	// 头部
	public String header() {
		return "header";
	}

	public Set<Menu> getMenuSet() {
		return menuSet;
	}

	public void setMenuSet(Set<Menu> menuSet) {
		this.menuSet = menuSet;
	}

}